//
//  ViewController.m
//  Masonry
//
//  Created by dllo on 15/11/17.
//  Copyright © 2015年 张树林. All rights reserved.
//

#import "ViewController.h"
#import <Masonry.h>

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    UIView *view = [[UIView alloc] init];
    
//    给view背景颜色
    view.backgroundColor = [UIColor yellowColor];
    
    [self.view addSubview:view];
    
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.view);
        make.size.mas_equalTo(CGSizeMake(300, 300));
    }];
    
    //1. make只负责增加新的约束, 但是不能同时出现两条针对同一对象的约束, 否则会报错
    //2. update方法针对上面的情况, 会更新约束, 以确保不会出现两条相同的约束.
    //3. remake方法会清除之前所有的约束, 并重新创建一次
    
    UIView *view2 = [[UIView alloc] init];
    view2.backgroundColor = [UIColor redColor];
    
    // 一定要先将view贴到上级视图上再创建约束, 否则会报错
    [self.view addSubview:view2];
    
    [view2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view).with.insets(UIEdgeInsetsMake(10, 10, 10, 10));
    }];
    
    // 两个高度为150的view, 居中并且等宽, 等间距, 宽度自动计算
    
    UIView *view3 = [[UIView alloc] init];
    view3.backgroundColor = [UIColor blueColor];
    [self.view addSubview:view3];
    
    UIView *view4 = [[UIView alloc] init];
    view4.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:view4];
    
    [view3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.view.mas_centerY);
        make.left.equalTo(self.view).with.offset(15);
        make.right.equalTo(view4.mas_left).with.offset(20);
        make.height.mas_equalTo(150);
        make.width.equalTo(view4);
        
    }];
    
    [view4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.view.mas_centerY);
        make.left.equalTo(view3.mas_right).with.offset(15);
        make.right.equalTo(self.view).with.offset(-15);
        make.height.equalTo(view3);
        make.width.equalTo(view3);
        
    }];
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
